package com.yunkaweilai.android.view.dialog.member;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.base.BaseDialog;
import com.github.lazylibrary.util.ToastUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.activity.operation.MemberLock.LockActivity;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.constants.CommonConstants;
import com.yunkaweilai.android.model.Event;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2017/6/27.
 */

public class MemberDelDialogForLock extends BaseDialog<MemberDelDialogForLock> {

    TextView idTvDel;
    TextView idTvClose;
    TextView idTVContent;
    private Context context;
    private ImageView idImgClose;
    private String id;

    public MemberDelDialogForLock(Context context, String id) {
        super(context);
        this.context = context;
        this.id = id;

    }

    @SuppressLint("ResourceAsColor")
    @Override
    public View onCreateView() {
        widthScale(0);
        //showAnim(new Swing());
        //dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_del_confirm, null);
        idTvDel = (TextView) inflate.findViewById(R.id.id_tv_del);
        idTvClose = (TextView) inflate.findViewById(R.id.id_tv_close);
        idImgClose = ((ImageView) inflate.findViewById(R.id.id_img_close));
        idTVContent = ((TextView) inflate.findViewById(R.id.id_edt_type_name));
        idTVContent.setText("请确认删除，删除后数据不可恢复？");
//        idTVContent.setText(Html.fromHtml( "<font color='#F53435'>请确认删除，删除后数据不可恢复？</font>"));
        //设置背景颜色，和背景的透明圆弧角度
        inflate.setBackgroundDrawable(
                CornerUtils.cornerDrawable(Color.parseColor("#f8f9fa"), dp2px(10)));

        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        idTvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initHttp();
            }
        });
        idImgClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void initHttp(){
        HttpRequest.postUrl(Api.DEL_MEMBER)
                .addParams("id",id)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mContext, json);
                        if (checkCode){
                            EventBus.getDefault().post(new Event.TypeEvent(CommonConstants.MEMBER_LIST, true));
                            ((LockActivity)mContext).finish();
                        }
                        dismiss();
                    }

                    @Override
                    public void onError(Exception e) {
                        ToastUtils.showToast(mContext,"系统错误");
                        dismiss();
                    }
                });
    }

}